package org.hismig.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @declare: //TODO <br />
 *           This class created by Vansion.Hopihit on 2012-07-04 <br />
 *           <a href="mailto:vansionhopihit@gmail.com">Contact Me</a>
 * @version 1.0
 * @author Vansion.Hopihit
 * 
 */
public class DateTool {

	private static SimpleDateFormat normalDateSDF;
	private static SimpleDateFormat shortDateSDF;

	private static SimpleDateFormat normalTimeSDF;
	private static SimpleDateFormat shortTimeSDF;

	private static SimpleDateFormat normalDateTimeSDF;

	public static SimpleDateFormat getNormalDateSDF() {
		if (null == normalDateSDF) {
			normalDateSDF = new SimpleDateFormat("yyyy-MM-dd");
		}
		return normalDateSDF;
	}
	public static SimpleDateFormat getShortDateSDF() {
		if (null == shortDateSDF) {
			shortDateSDF = new SimpleDateFormat("yyyyMMdd");
		}
		return shortDateSDF;
	}
	public static SimpleDateFormat getNormalTimeSDF() {
		if (null == normalTimeSDF) {
			normalTimeSDF = new SimpleDateFormat("HH:mm:ss");
		}
		return normalTimeSDF;
	}
	public static SimpleDateFormat getShortTimeSDF() {
		if (null == shortTimeSDF) {
			shortTimeSDF = new SimpleDateFormat("HHmmss");
		}
		return shortTimeSDF;
	}

	public static String getNormalDate(Date date) {
		if (null == date) {
			return null;
		}

		return getNormalDateSDF().format(date);
	}

	public static String getShortDate(Date date) {
		if (null == date) {
			return null;
		}

		return getShortDateSDF().format(date);
	}

	public static String getNormalTime(Date date) {
		if (null == date) {
			return null;
		}

		return getNormalTimeSDF().format(date);
	}

	public static String getShortTime(Date date) {
		if (null == date) {
			return null;
		}

		return getShortTimeSDF().format(date);
	}

	public static String getNormalDateTime(Date date) {
		if (null == date) {
			return null;
		}

		return getNormalDateTimeSDF().format(date);
	}

	public static SimpleDateFormat getNormalDateTimeSDF() {
		if (null == normalDateTimeSDF) {
			normalDateTimeSDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		}

		return normalDateTimeSDF;
	}

	public static Date CountDate(int scope) {
		Date theDay;
		if (0 != scope) {
			Calendar calendar = Calendar.getInstance();
			calendar.add(Calendar.DAY_OF_MONTH, scope);
			theDay = calendar.getTime();
		} else {
			theDay = new Date();
		}

		return theDay;
	}

	public static String getFormateRanTime(long ranTime) {

		String ret = "";

		long day = ranTime / 1000 / (60 * 60 * 24);
		long hour = (ranTime / 1000 / (60 * 60)) % 24;
		long min = (ranTime / 1000 / 60) % 60;
		long sec = ranTime / 1000 % 60;

		if (0 < day) {
			ret += day + "天";
		}

		if (0 < hour) {
			ret += hour + "小时";
		}

		if (0 < min) {
			ret += min + "分钟";
		}

		if (0 < sec) {
			ret += sec + "秒";
		}

		return ret;
	}
}
